#include <iostream>
#include <algorithm>
using namespace std;

void gcd0(int a, int b, int& c) {
	int tmpl = a;
	if (a > b) tmpl = b;
    for (int i = tmpl; i >= 1; --i) 
        if ( a % i ==0 && b % i == 0) {
            c = i;
            return;
        }
}

void gcd1(int a, int b, int& c) {
    if (a < b) swap(a,b);
    while (1) {
        if (a % b == 0) {
            c = b;
            return;
        } else {
            int foo = b;
            b = a % b;
            a = foo;
        }
    }
}

void gcd2(int a, int b, int& c) {
    if (a < b) swap(a,b);
    if (a % b == 0) {
        c = b;
        return;
    } else {
        gcd2(b, a % b, c);
    }
}
    
int main() {
    int foo, bar;
    cout << "Enter two integers: ";
    while(cin >> foo >> bar) {
        int g;
        gcd2(foo, bar, g);
        cout << "The greatest common divisor of " << foo 
             << " and " << bar << " is " << g << endl;
        cout << "Enter two integers: ";
    }
    return 0;
}
